<template>
	<view>
		<uni-card class="dhCard" v-for="(item,index) in list" :key="index" @click="goDetails(item)">
			<view class="content">
				<image src="../../../static/partyBuilding/vote/1.png" mode=""></image>
				<view class="title">
					{{item.title}}
				</view>
			</view>

			<view class="actions" slot="{actions}">
				<view class="actions-left">
					<view class="title" :class="item.status ? 'succTit':'errTit'">
						{{ item.status ? '活动进行中':'已结束' }}
					</view>
					<view class="end-time">
						截止时间：{{item.endTime}}
					</view>
				</view>
				<view class="actions-right">
					{{item.numberVote}}人参与
				</view>
			</view>
		</uni-card>
		<u-toast ref="uToast"></u-toast>
		<u-loadmore lineColor="#1CD29B" dashed line :status="status" :loading-text="loadingText"
			:loadmore-text="loadmoreText" :nomore-text="nomoreText" />
	</view>
</template>

<script>
	import {
		getVoteList
	} from '../../../api/voteApi/index.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				loadingText: '加载中',
				loadmoreText: '加载更多',
				nomoreText: '已经到底了',
				list: [
					// 	{
					// 	status: true,
					// 	endTime: '2024-05-27',
					// 	number: '426',
					// 	title: '看看谁是你心中最美的人',
					// 	desc:'有的党员只满足于干好手头工作，模范带头作用发挥不明显”“有的党员干部战场鼓动方法单一，对如何搞好战时政治工作研究不深，创新意识有待加强”……前不久'
					// }, {
					// 	status: false,
					// 	endTime: '2024-04-22',
					// 	number: '222',
					// 	title: '快来选择你心中的村长',
					// 	desc:'越是任务重越要沉下心来，通过及时交流明确方向。”全教导员介绍，常态讲评干部、交流经验、研战谋战，'
					// }, 
				],
				params: {
					pageNum: 1,
					pageSize: 10,
				},
				total:null
			}
		},
		onShow() {
			this.list = []
			this.Init()
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.params.pageNum = 1;
			this.status = 'loading'
			// 请求接口
			this.list = []
			this.Init()
		},
		// 上拉加载
		onReachBottom() {
			// 当列表数量大于总数量，return
			this.status = 'loading'
			if (this.list.length >= this.total) return this.status = 'nomore';;
			this.params.pageNum++;
			// 请求接口
			this.Init()
		},
		methods: {
			// 获取投票活动list
			async Init() {
				const result = await getVoteList(this.params)
				const data = result.data.result;
				console.log('123',data)
				this.total = data.total;//总数
				const list = data.list;
				list.forEach(item => {
					item.endTime = item.endTime.slice(0, 10)
				});
				this.list = this.list.concat(list);//合并数组
				uni.stopPullDownRefresh(); //刷新图片关闭
				if (this.list.length >= this.total) {
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}

			},
			goDetails(item) {
				if (!item.status) return this.$refs.uToast.show({
					type: 'error',
					icon: false,
					message: "活动已经结束了，去看看其他的吧！",
				});
				uni.navigateTo({
					url: `/pages/partyBuilding/vote/details?data=${encodeURIComponent(JSON.stringify(item))}`
				})
			}
		},
	}
</script>

<style scoped lang="scss">
	::v-deep.dhCard {
		.uni-card__content {
			font-size: 30rpx;

			.content {
				display: flex;
				align-items: center;

				.title {
					color: black !important;
					font-weight: 600;
				}

				image {
					width: 30rpx;
					height: 30rpx;
				}
			}
		}

		.uni-card__actions {
			padding: 20rpx;

			.actions {
				display: flex;
				justify-content: space-between;

				.actions-left {
					display: flex;

					:nth-child(1) {
						margin-right: 20rpx;
						font-weight: 600;
					}

					.succTit {
						color: green;
					}

					.errTit {
						color: red;
					}
				}
			}
		}
	}
</style>